﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leo.Entities;
using Leo.BL;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace VeterinariaDrLeo.Controllers
{
    public class RolController : Controller
    {
        //
        // GET: /Rol/
        [Dependency]
        public IRolBL rolBl { get; set; }
        public ActionResult Index()
        {
            var listarRol = rolBl.GetAllFromRolesByCriterio("");
            return View(listarRol);
        }

        [HttpPost]
        public ActionResult Index(string criterio = "")
        {
            var listarRol = rolBl.GetAllFromRolesByCriterio(criterio);
            return View(listarRol);
        }

        public ActionResult Create()
        {
            var rol = rolBl.GetAllFromRolesByCriterio("");
            return View();
        }

        [HttpPost]
        public ActionResult Create(Rol rol)
        {
            try
            {
                rolBl.AddRol(rol);
                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }

        }

        public ActionResult Edit(Int32 id)
        {
            var rol = rolBl.GetFromRolesByID(id);
            return View(rol);
        }

        [HttpPost]
        public ActionResult Edit(int id, Rol rol)
        {
            try
            {
                rolBl.UpdateRol(rol);
                return RedirectToAction("index");
                
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Delete(int id)
        {
            rolBl.RemoveRol(id);
            return RedirectToAction("index");
            
        }

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                return RedirectToAction("index");
            }

            catch
            {
                return View();
            }
        }
    }
}
